package com.yanqu.road.entity.kuang;

import com.yanqu.road.entity.config.system.NormalWeightItem;
import com.yanqu.road.entity.config.system.PropertyWeightItem;
import com.yanqu.road.entity.enums.kuang.eKuangAttributeType;
import com.yanqu.road.entity.kuang.config.KuangEquipmentConfig;
import com.yanqu.road.entity.kuang.config.KuangPlaceConfig;
import com.yanqu.road.entity.kuang.config.KuangSystemConfig;
import com.yanqu.road.entity.kuang.config.entity.KuangTimeConfig;
import com.yanqu.road.utils.property.PropertyHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 矿山配置
 */
public class KuangConfig {

    private Map<Integer, KuangEquipmentConfig> equipmentConfigMap = new ConcurrentHashMap<>();

    private Map<Integer, KuangPlaceConfig> placeConfigMap = new ConcurrentHashMap<>();

    /**
     * 最大抽取装备数量
     */
    public static final int MAX_DRAW_EQUIPMENT_CNT = 3;

    /**
     * 装备品质抽取权重   轮次天数，权重
     */
    private Map<Integer, List<NormalWeightItem>> equipmentQualityWeightListMap = new ConcurrentHashMap<>();

    /**
     * 属性最大值
     */
    private Map<eKuangAttributeType, Long> maxAttributeMap = new ConcurrentHashMap<>();

    /**
     * 仙力计算参数
     */
    private List<Integer> abilityParamList = new ArrayList<>();

    /**
     * 时间配置
     */
    private KuangTimeConfig timeConfig = null;

    /**
     * 分数结束条件
     */
    private long battleScoreEndCondition;

    /**
     * 头像配置
     */
    private List<List<Integer>> profileRadiusList = new ArrayList<>();

    /**
     * 技能配置  等级，类型，参数
     */
    private Map<Integer, Map<Integer,Integer>> skillParamMap = new ConcurrentHashMap<>();

    /**
     * 后台配置
     */
    private KuangSystemConfig kuangSystemConfig = new KuangSystemConfig();

    private int personMaxRank;

    private int groupMaxRank;

    public int getPersonMaxRank() {
        return personMaxRank;
    }

    public void setPersonMaxRank(int personMaxRank) {
        this.personMaxRank = personMaxRank;
    }

    public int getGroupMaxRank() {
        return groupMaxRank;
    }

    public void setGroupMaxRank(int groupMaxRank) {
        this.groupMaxRank = groupMaxRank;
    }

    public KuangSystemConfig getKuangSystemConfig() {
        return kuangSystemConfig;
    }

    public void setKuangSystemConfig(KuangSystemConfig kuangSystemConfig) {
        this.kuangSystemConfig = kuangSystemConfig;
    }

    public KuangConfig() {

    }

    public Map<Integer, KuangEquipmentConfig> getEquipmentConfigMap() {
        return equipmentConfigMap;
    }

    public KuangEquipmentConfig getEquipmentConfig(int equipId) {
        return equipmentConfigMap.get(equipId);
    }

    public void setEquipmentConfigMap(Map<Integer, KuangEquipmentConfig> equipmentConfigMap) {
        this.equipmentConfigMap = equipmentConfigMap;
    }

    public KuangPlaceConfig getPlaceConfig(int placeId) {
        return placeConfigMap.get(placeId);
    }

    public Map<Integer, KuangPlaceConfig> getPlaceConfigMap() {
        return placeConfigMap;
    }

    public void setPlaceConfigMap(Map<Integer, KuangPlaceConfig> placeConfigMap) {
        this.placeConfigMap = placeConfigMap;
    }

    public KuangTimeConfig getTimeConfig() {
        return timeConfig;
    }

    public void setTimeConfig(KuangTimeConfig timeConfig) {
        this.timeConfig = timeConfig;
    }

    public long getBattleStartTime(int roundDay) {
        if (timeConfig == null) {
            return 0;
        }
        if (roundDay == 1) {
            return timeConfig.getDay1BattleStartTime();
        } else if (roundDay == 2) {
            return timeConfig.getDay2BattleStartTime();
        }
        return 0;
    }


    public long getBattleEndTime(int roundDay) {
        if (timeConfig == null) {
            return 0;
        }
        if (roundDay == 1) {
            return timeConfig.getDay1BattleEndTime();
        } else if (roundDay == 2) {
            return timeConfig.getDay2BattleEndTime();
        }
        return 0;
    }

    public long getBattleScoreEndCondition() {
        return battleScoreEndCondition;
    }

    public void setBattleScoreEndCondition(long battleScoreEndCondition) {
        this.battleScoreEndCondition = battleScoreEndCondition;
    }

    public Map<Integer, List<NormalWeightItem>> getEquipmentQualityWeightListMap() {
        return equipmentQualityWeightListMap;
    }

    public void setEquipmentQualityWeightListMap(Map<Integer, List<NormalWeightItem>> equipmentQualityWeightListMap) {
        this.equipmentQualityWeightListMap = equipmentQualityWeightListMap;
    }

    public Map<eKuangAttributeType, Long> getMaxAttributeMap() {
        return maxAttributeMap;
    }

    public void setMaxAttributeMap(Map<eKuangAttributeType, Long> maxAttributeMap) {
        this.maxAttributeMap = maxAttributeMap;
    }

    public List<Integer> getAbilityParamList() {
        return abilityParamList;
    }

    public void setAbilityParamList(List<Integer> abilityParamList) {
        this.abilityParamList = abilityParamList;
    }

    public List<List<Integer>> getProfileRadiusList() {
        return profileRadiusList;
    }

    public void setProfileRadiusList(List<List<Integer>> profileRadiusList) {
        this.profileRadiusList = profileRadiusList;
    }

    public Map<Integer, Map<Integer,Integer>> getSkillParamMap() {
        return skillParamMap;
    }

    public void setSkillParamMap(Map<Integer, Map<Integer,Integer>> skillParamMap) {
        this.skillParamMap = skillParamMap;
    }

    public int getProfileRadius(int killNum) {
        int radius = 50;
        for (List<Integer> list : profileRadiusList) {
            if (killNum >= list.get(0)) {
                radius = list.get(1);
            }
        }
        return radius;
    }

    /**
     * 活动期间 【首日活动打造装备准备期开始时间，领奖期开始】
     */
    public boolean isActivityTime() {
        if (timeConfig == null) {
            return false;
        }
        long currentTimeMillis = System.currentTimeMillis();
        return currentTimeMillis >= timeConfig.getDay1BeginTime() && currentTimeMillis <= timeConfig.getDay2BattleEndTime();
    }

    /**
     * 活动是否战斗中【开战首日、次日战斗开始时间，开战首日、次日战斗结束时间】
     */
    public boolean isBattleTime(int roundDay) {
        if (timeConfig == null) {
            return false;
        }
        long currentTimeMillis = System.currentTimeMillis();
        return roundDay == 1 && currentTimeMillis >= timeConfig.getDay1BattleStartTime() && currentTimeMillis <= timeConfig.getDay1BattleEndTime()
                || roundDay == 2 && currentTimeMillis >= timeConfig.getDay2BattleStartTime() && currentTimeMillis <= timeConfig.getDay2BattleEndTime();
    }

    /**
     * 活动是否开启 【开战首日、次日战斗开始准备时间，开战首日、次日战斗结束时间】
     */
    public boolean isOpenTime(int roundDay) {
        if (timeConfig == null) {
            return false;
        }
        long currentTimeMillis = System.currentTimeMillis();
        return roundDay == 1 && currentTimeMillis >= timeConfig.getDay1BattlePrepareTime() && currentTimeMillis <= timeConfig.getDay1BattleEndTime()
                || roundDay == 2 && currentTimeMillis >= timeConfig.getDay2BattlePrepareTime() && currentTimeMillis <= timeConfig.getDay2BattleEndTime();
    }
}
